<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../css/common.css" media="all">

	</head>
	<body>

		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form test_edit" lay-filter="test_detail">
					<div class="layui-card">
						<div class="layui-card-body">
							
							<div class="layui-form-item">
								<label class="layui-form-label"><text class='text_red_color'>*</text>产品类型：</label>
								<div class="layui-input-block product"></div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label"><text class='text_red_color'>*</text>返现金额：</label>
								<div class="layui-input-block">
									<input type="text" name="back_amount" lay-verify="required|number" placeholder="请输入返现金额" autocomplete="off"
									 class="layui-input">
								</div>
							</div>
							
							<div class="layui-form-item">
								<label class="layui-form-label">购机红包：</label>
								<div class="layui-input-block">
									<input type="text" name="back_packet" lay-verify="number"  placeholder="请输入购机红包" autocomplete="off"
									 class="layui-input">
								</div>
							</div>
							
							<div class="layui-form-item">
								<label class="layui-form-label">押金金额：</label>
								<div class="layui-input-block">
									<input type="text" name="deposit_amount" placeholder="请输入押金金额" autocomplete="off"
									 class="layui-input">
								</div>
							</div>
							
							<div class="layui-form-item">
								<label class="layui-form-label">返现到期：</label>
								<div class="layui-input-block">
									 <input type="text" name="back_expire" id="date" placeholder="返现到期" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">返现到期金额：</label>
								<div class="layui-input-block">
									 <input type="text" name="back_expire_amount"   placeholder="返现到期金额" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">到期购机红包：</label>
								<div class="layui-input-block">
									 <input type="text" name="back_expire_packet"   placeholder="到期购机红包" autocomplete="off" class="layui-input">
								</div>
							</div>
							
							
							<div class="layui-form-item">
								<label class="layui-form-label">机身编号：</label>
								<div class="layui-input-block">
									<input type="text" name="pos_sn_pre" placeholder="请输入支付公司及产品类型(例:K205T0H)" autocomplete="off"
									 class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">序列号范围：</label>
									<div class="layui-input-inline" style="width: 100px;">
										<input type="text" name="sn_start" placeholder="开始序列号" autocomplete="off" class="layui-input">
									</div>
									<div class="layui-form-mid">-</div>
									<div class="layui-input-inline" style="width: 100px;">
										<input type="text" name="sn_end" placeholder="结束序列号" autocomplete="off" class="layui-input">
									</div>
									<button type="button" class="layui-btn layui-btn-normal" onclick="createnum()">生成</button>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">机具序列号：</label>
								<div class="layui-input-block">
									<textarea placeholder="请输入机具序列号" name="pos_sn" class="layui-textarea"></textarea>
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">入库备注：</label>
								<div class="layui-input-block">
									<textarea placeholder="请输入库备注" name="description" class="layui-textarea"></textarea>
								</div>
							</div>
						</div>
					</div>

					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<!-- <button type="reset" class="layui-btn layui-btn-primary">重置</button> -->
								<button class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../js/jquery.min.js"></script>
		<script src="../../../js/jquery.jqprint-0.3.js"></script>
		<script src="../../../js/common.js"></script>
		<script>
			var _data = {
				// id: getParam('id')
			}
			// console.log(_data.id);

			layui.config({
				base: '../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'laytpl', 'laydate', 'layedit'], function() {
				var $ = layui.$,
					admin = layui.admin,
					layedit = layui.layedit,
					laytpl = layui.laytpl,
					laydate = layui.laydate,
					form = layui.form;
				
				initproductshow1('radio')
				var pos_sn_arr = [],
					img_arr1 = [],
					img_arr2 = [];

				var index = layedit.build('demo_editor', {
					tool: ['strong' //加粗
						, 'italic' //斜体
						, 'underline' //下划线
						, 'del' //删除线

						, '|' //分割线

						, 'left' //左对齐
						, 'center' //居中对齐
						, 'right' //右对齐
						, 'link' //超链接
						, 'unlink' //清除链接
						, 'face' //表情
					]
				});

				on_off_show('radio')
				if (_data.id) {
					initdata();
				} else {
					initnews_catshow('option');
				}
				
				laydate.render({
				    elem: '#date'
				});
				
				//监听提交
				form.on('submit(demo1)', function(data) {
					var data = data.field;
					_data.product = data.product;
					_data.back_amount = data.back_amount;
					_data.op_remark = data.op_remark;
					_data.back_expire = data.back_expire;
					_data.deposit_amount = data.deposit_amount;
					_data.back_packet = data.back_packet;
					// _data = Object.assign(_data, data);
					// console.log(data.pos_sn.replace(/[\r\n]/g,""));
					pos_sn_arr = [];
					var pos_sn = data.pos_sn.replace(/[\r\n]/g,"").split(',')
					for (var i = 0; i < pos_sn.length; i++) {
						if(pos_sn[i]){
							pos_sn_arr.push({
								'pos_sn': pos_sn[i].replace(/ /g,'')
							})
						}
					}
					_data.pos_data = JSON.stringify(pos_sn_arr);
					
					layer.confirm('确定提交数据？', function() {
						loading();
						if (!_data.id) {
							submitdata(server.querypos_in);
						} else {
							submitdata();
						}
					}, function() {
						layer.msg('取消操作');
					});
					return false;
				});

				function submitdata(_url) {
					$.post(_url, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								layer.msg(res.msg);
								layer.closeAll('loading');
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}

				window.createnum = function() {

					var pos_sn_pre = $('input[name=pos_sn_pre]').val(),
						sn_start = $('input[name=sn_start]').val(),
						sn_end = $('input[name=sn_end]').val();

					if (!pos_sn_pre) {
						layer.msg('请输入机身编号')
					} else if (!sn_start || sn_start.length > 4 || !zorenumReg.test(Number(sn_start))) {
						console.log(zorenumReg.test(sn_start));
						layer.msg('开始序列号必须为小于4位的纯数字')
					} else if (!sn_end || sn_end.length > 4 || !zorenumReg.test(Number(sn_end))) {
						layer.msg('结束序列号必须为小于4位的纯数字')
					} else if (sn_start >= sn_end) {
						layer.msg('结束序列号必须大于等于开始序列号')
					} else {
						var numlength = Number(sn_end) - Number(sn_start),
							pos_sn_html = ''
							
						for (var i = 0; i <= numlength; i++) {
							var pos_sn = String(Number(sn_start) + Number(i))
							pos_sn_html += (pos_sn_pre + PrefixInteger(pos_sn,4) + ',\n').replace(/ /g,'')
							/* pos_sn_arr.push({
								'pos_sn': pos_sn_pre + PrefixInteger(pos_sn,4)
							}) */
						}
						$('textarea[name=pos_sn]').val(pos_sn_html)
					}

				}

				function initdata() {
					$.get(server.querynewsdetail, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								var data = res.news_detail
								var data1 = res.news_cat.data

								var cathtml = '<option value="">全部</option>';
								for (var i = 0; i < data1.length; i++) {
									cathtml += '<option value=' + data1[i].id + '>' + data1[i].name + '</option>'
								}
								$('.catid').append(cathtml)

								form.val("test_detail", data.data);
								form.render();

								data.data.thumbnail ? createli(data.data.thumbnail, 'showimg', '1') : ''
								layedit.setContent(index, data.data.content)

							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}

			});
		</script>
	</body>
</html>
